#include "ohos_rtp_transceiver.h"
#include "ohos_rtp_sender.h"
#include "ohos_rtp_receiver.h"

namespace ohoswebrtc {

OHOSRtpTransceiver::OHOSRtpTransceiver(
    rtc::scoped_refptr<webrtc::RtpTransceiverInterface> rtp_transceiver, rtc::scoped_refptr<OHOSPeerConnectionFactoryInterface> peer_connection_factory)
    : rtp_transceiver_(rtp_transceiver),
      peer_connection_factory_(peer_connection_factory) {
  RTC_LOG(LS_INFO) << __FUNCTION__ << ": Ctor";
}

const absl::optional<std::string> OHOSRtpTransceiver::mid() const {
  return rtp_transceiver_->mid();
}

absl::optional<webrtc::RtpTransceiverDirection> OHOSRtpTransceiver::fired_direction() const {
  return rtp_transceiver_->fired_direction();
}

absl::optional<webrtc::RtpTransceiverDirection> OHOSRtpTransceiver::current_direction() const {
  return rtp_transceiver_->current_direction();
}

rtc::scoped_refptr<OHOSRtpSenderInterface> OHOSRtpTransceiver::sender() const {
  if (rtp_transceiver_->sender()) {
    return rtc::scoped_refptr<OHOSRtpSenderInterface>(
            new rtc::RefCountedObject<OHOSRtpSender>(rtp_transceiver_->sender(), peer_connection_factory_));
  }
  return rtc::scoped_refptr<OHOSRtpSenderInterface>();
}

rtc::scoped_refptr<OHOSRtpReceiverInterface> OHOSRtpTransceiver::receiver() const {
  if (rtp_transceiver_->receiver()) {
    return rtc::scoped_refptr<OHOSRtpReceiverInterface>(
            new rtc::RefCountedObject<OHOSRtpReceiver>(rtp_transceiver_->receiver(), peer_connection_factory_));
  }
  return rtc::scoped_refptr<OHOSRtpReceiverInterface>();
}

OHOSRtpTransceiver::~OHOSRtpTransceiver() {
  RTC_LOG(LS_INFO) << __FUNCTION__ << ": Dtor";
}

}  // namespace ohoswebrtc